package com.tudouji.project.bill.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.bill.domain.Discount;
import com.tudouji.project.bill.service.IDiscountService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 折扣Controller
 * 
 * @author tudouji
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/bill/discount")
public class DiscountController extends BaseController
{
    @Autowired
    private IDiscountService discountService;

    /**
     * 查询折扣列表
     */
    @PreAuthorize("@ss.hasPermi('bill:discount:list')")
    @GetMapping("/list")
    public TableDataInfo list(Discount discount)
    {
        startPage();
        List<Discount> list = discountService.selectDiscountList(discount);
        return getDataTable(list);
    }


    /**
     * 导出折扣列表
     */
    @PreAuthorize("@ss.hasPermi('bill:discount:export')")
    @Log(title = "折扣", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Discount discount)
    {
        List<Discount> list = discountService.selectDiscountList(discount);
        ExcelUtil<Discount> util = new ExcelUtil<Discount>(Discount.class);
        return util.exportExcel(list, "discount");
    }

    /**
     * 获取折扣详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:discount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(discountService.selectDiscountById(id));
    }

    /**
     * 新增折扣
     */
    @PreAuthorize("@ss.hasPermi('bill:discount:add')")
    @Log(title = "折扣", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Discount discount)
    {
        return toAjax(discountService.insertDiscount(discount));
    }

    /**
     * 修改折扣
     */
    @PreAuthorize("@ss.hasPermi('bill:discount:edit')")
    @Log(title = "折扣", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Discount discount)
    {
        return toAjax(discountService.updateDiscount(discount));
    }

    /**
     * 删除折扣
     */
    @PreAuthorize("@ss.hasPermi('bill:discount:remove')")
    @Log(title = "折扣", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(discountService.deleteDiscountByIds(ids));
    }
}
